package impl

import (
	"gitee.com/jasmine456/devcloud-mini/cmdb/apps/resource"
	"github.com/go-playground/validator/v10"
	"github.com/infraboard/mcube/ioc"
	"github.com/infraboard/mcube/ioc/config/logger"
	ioc_mongo "github.com/infraboard/mcube/ioc/config/mongo"
	"github.com/rs/zerolog"
	"go.mongodb.org/mongo-driver/mongo"
)

func init() {
	ioc.Controller().Registry(&impl{})
}

// resource 控制器
type impl struct {
	// ioc托管继承
	ioc.ObjectImpl
	// 实现了对外的rpc
	resource.UnimplementedRPCServer
	// 需要存入的数据库
	col *mongo.Collection
	//	模块的日志
	log *zerolog.Logger
	//	校验器
	validate *validator.Validate
}

func (i *impl) Init() error {
	// 需要依赖mongodb
	// 通过ioc的依赖注入 来通过配置文件自动注入该对象
	i.col = ioc_mongo.DB().Collection(resource.AppName)
	i.log = logger.Sub(resource.AppName)
	i.validate = validator.New()
	return nil
}

func (i *impl) Name() string {
	return resource.AppName
}
